﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package zasp.Classes {
    import flash.events.*;
    import flash.display.*;
    import zasp.Util.*;
    import zasp.Display.*;

    public class ZaspTrackerDebug {

        protected var spinnerF2F:FunkySpinner = null;
        protected var spinnerEMA:FunkySpinner = null;
        protected var spinnerOEF:FunkySpinner = null;
        protected var fullRedraw:FullRedrawForcer = null;
        protected var keysActive:Boolean = false;
        protected var m_sprite:Sprite = null;
        protected var baseTracker:ZaspTrackerBase = null;
        protected var useSpinnerOef:Boolean = false;

        public function ZaspTrackerDebug(_arg1:ZaspTrackerBase, _arg2:Boolean=false){
            CircularBuffer.test();
            SumSampler.test();
            this.baseTracker = _arg1;
            this.useSpinnerOef = _arg2;
            this.m_sprite = new Sprite();
            this.m_sprite.addEventListener(Event.ADDED_TO_STAGE, this.added_to_stage, false, 0, true);
        }
        public function sample(_arg1:Number, _arg2:Number):void{
            if (null != this.spinnerF2F){
                this.spinnerF2F.sample(_arg1);
            };
            if (null != this.spinnerEMA){
                this.spinnerEMA.sample(this.baseTracker.f2f);
            };
            if (null != this.spinnerOEF){
                this.spinnerOEF.sample(_arg2);
            };
        }
        private function added_to_stage(_arg1:Event):void{
            this.m_sprite.removeEventListener(Event.ADDED_TO_STAGE, this.added_to_stage, false);
            this.m_sprite.addEventListener(Event.REMOVED_FROM_STAGE, this.removed_from_stage, false, 0, true);
            this.m_sprite.stage.addEventListener(KeyboardEvent.KEY_DOWN, this.key_down, false, 0, true);
        }
        private function removed_from_stage(_arg1:Event):void{
            this.m_sprite.stage.removeEventListener(KeyboardEvent.KEY_DOWN, this.key_down, false);
            this.m_sprite.removeEventListener(Event.REMOVED_FROM_STAGE, this.removed_from_stage, false);
            this.m_sprite.addEventListener(Event.ADDED_TO_STAGE, this.added_to_stage, false, 0, true);
        }
        private function key_down(_arg1:KeyboardEvent):void{
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:int;
            var _local6:int;
            var _local7:int;
            var _local8:int;
            if (_arg1.keyCode == 219){
                this.keyCapture = !(this.keyCapture);
                if (this.keyCapture){
                    trace("keyboard input for ZASP enabled");
                } else {
                    trace("keyboard input for ZASP disnabled");
                };
            };
            if (!this.keyCapture){
                return;
            };
            switch (_arg1.keyCode){
                case 82:
                    this.baseTracker.log_report();
                    break;
                case 49:
                    trace("disabling all cacheAsBitmap");
                    _local2 = this.recurse(this.m_sprite.stage, this.isCacheAsBitmap, this.disable_CacheAsBitmap);
                    trace(("  num: " + _local2));
                    break;
                case 50:
                    trace("enabling all cacheAsBitmap");
                    _local2 = this.recurse(this.m_sprite.stage, this.isAnything, this.enable_CacheAsBitmap);
                    trace(("  num: " + _local2));
                    break;
                case 51:
                    trace("toggling Shapes cacheAsBitmap");
                    _local2 = this.recurse(this.m_sprite.stage, this.isShape, this.toggle_CacheAsBitmap);
                    trace(("  num: " + _local2));
                    break;
                case 52:
                    trace("toggling Sprites cacheAsBitmap");
                    _local2 = this.recurse(this.m_sprite.stage, this.isSprite, this.toggle_CacheAsBitmap);
                    trace(("  num: " + _local2));
                    break;
                case 54:
                    if (this.areSpinnersActive){
                        trace("deactivating spinners");
                        this.deactivateSpinners();
                    } else {
                        trace("activating spinners");
                        this.activateSpinners();
                    };
                    break;
                case 55:
                    if (this.isFullRedrawActive){
                        trace("deactivating forced full redraw");
                        this.deactivateFullRedraw();
                    } else {
                        trace("activating forced full redraw");
                        this.activateFullRedraw();
                    };
                    break;
                case 56:
                    trace("bringing spinners to front");
                    if (this.m_sprite.parent != null){
                        this.m_sprite.parent.setChildIndex(this.m_sprite, (this.m_sprite.parent.numChildren - 1));
                    };
                    break;
                case 48:
                    trace("logging empties");
                    _local2 = this.recurse(this.m_sprite.stage, this.isEmpty, this.log);
                    trace(("  num: " + _local2));
                    break;
                case 86:
                    trace("pruning empties");
                    _local2 = this.recurse(this.m_sprite.stage, this.isAnything, this.prune_empties);
                    trace(("  num: " + _local2));
                    break;
                case 57:
                    trace("counting objects cacheAsBitmap");
                    _local3 = this.recurse(this.m_sprite.stage, this.isAnything, this.nothing);
                    _local4 = this.recurse(this.m_sprite.stage, this.isCacheAsBitmap, this.nothing);
                    _local5 = this.recurse(this.m_sprite.stage, this.isNotCacheAsBitmap, this.nothing);
                    trace(("  has: " + _local4));
                    trace(("  not: " + _local5));
                    trace(("  all: " + _local3));
                    _local6 = this.recurse(this.m_sprite.stage, this.isShape, this.nothing);
                    trace(("num Shapes:      " + _local6));
                    _local7 = this.recurse(this.m_sprite.stage, this.isSprite, this.nothing);
                    trace(("num Sprites:     " + _local7));
                    _local8 = this.recurse(this.m_sprite.stage, this.isEmpty, this.nothing);
                    trace(("num empties:     " + _local8));
                    break;
            };
        }
        public function log_report():void{
            trace("PERFORMANCE REPORT DEBUG");
        }
        private function log(_arg1:DisplayObject):void{
            trace(_arg1);
            trace(("  name:        " + _arg1.name));
            trace(("  x:           " + _arg1.x));
            trace(("  y:           " + _arg1.y));
            trace(("  width:       " + _arg1.width));
            trace(("  height:      " + _arg1.height));
            trace(("  scaleX:      " + _arg1.scaleX));
            trace(("  scaleY:      " + _arg1.scaleY));
            trace(("  rotation:    " + _arg1.rotation));
            trace(("  cab:         " + _arg1.cacheAsBitmap));
            trace(("  visible:     " + _arg1.visible));
            trace(("  mouseX:      " + _arg1.mouseX));
            trace(("  mouseY:      " + _arg1.mouseY));
            var _local2:DisplayObjectContainer = (_arg1 as DisplayObjectContainer);
            if (null != _local2){
                trace(("  numChildren: " + _local2.numChildren));
            };
        }
        private function recurse(_arg1:DisplayObject, _arg2:Function, _arg3:Function):int{
            var _local6:int;
            if (null == _arg1){
                return (0);
            };
            var _local4:int;
            if (_arg2(_arg1)){
                _local4 = (_local4 + 1);
                _arg3(_arg1);
            };
            var _local5:DisplayObjectContainer = (_arg1 as DisplayObjectContainer);
            if (null != _local5){
                _local6 = 0;
                while (_local6 < _local5.numChildren) {
                    _local4 = (_local4 + this.recurse(_local5.getChildAt(_local6), _arg2, _arg3));
                    _local6++;
                };
            };
            return (_local4);
        }
        private function isShape(_arg1:DisplayObject):Boolean{
            return ((_arg1 is Shape));
        }
        private function isSprite(_arg1:DisplayObject):Boolean{
            return ((_arg1 is Sprite));
        }
        private function isCacheAsBitmap(_arg1:DisplayObject):Boolean{
            return (_arg1.cacheAsBitmap);
        }
        private function isNotCacheAsBitmap(_arg1:DisplayObject):Boolean{
            return (!(this.isCacheAsBitmap(_arg1)));
        }
        private function isFunkySpinner(_arg1:DisplayObject):Boolean{
            return ((_arg1 is FunkySpinner));
        }
        private function isAnything(_arg1:DisplayObject):Boolean{
            return (!((_arg1 == this.m_sprite.stage)));
        }
        private function togleVisibility(_arg1:DisplayObject):void{
            _arg1.visible = !(_arg1.visible);
        }
        private function toggle_CacheAsBitmap(_arg1:DisplayObject):void{
            _arg1.cacheAsBitmap = !(_arg1.cacheAsBitmap);
        }
        private function enable_CacheAsBitmap(_arg1:DisplayObject):void{
            _arg1.cacheAsBitmap = true;
        }
        private function disable_CacheAsBitmap(_arg1:DisplayObject):void{
            _arg1.cacheAsBitmap = false;
        }
        private function nothing(_arg1:DisplayObject):void{
        }
        public function get areSpinnersActive():Boolean{
            if (null != this.spinnerF2F){
                return (true);
            };
            if (null != this.spinnerEMA){
                return (true);
            };
            if (null != this.spinnerOEF){
                return (true);
            };
            return (false);
        }
        public function get sprite():Sprite{
            return (this.m_sprite);
        }
        public function activateSpinners():void{
            if (this.areSpinnersActive){
                return;
            };
            this.deactivateSpinners();
            var r:* = 50;
            var x:* = 475;
            var y:* = (5 + r);
            this.spinnerEMA = new FunkySpinner(x, y, r);
            x = (x + (1.4 * r));
            this.spinnerF2F = new FunkySpinner(x, y, r);
            x = (x + (1.4 * r));
            if (this.useSpinnerOef){
                this.spinnerOEF = new FunkySpinner(x, y, r);
            };
            try {
                this.m_sprite.addChild(this.spinnerF2F);
                this.m_sprite.addChild(this.spinnerEMA);
                if (null != this.spinnerOEF){
                    this.m_sprite.addChild(this.spinnerOEF);
                };
            } catch(err:Error) {
                spinnerF2F = null;
                spinnerEMA = null;
                spinnerOEF = null;
                throw (err);
            };
        }
        public function deactivateSpinners():void{
            if (null != this.spinnerF2F){
                this.m_sprite.removeChild(this.spinnerF2F);
            };
            if (null != this.spinnerEMA){
                this.m_sprite.removeChild(this.spinnerEMA);
            };
            if (null != this.spinnerOEF){
                this.m_sprite.removeChild(this.spinnerOEF);
            };
            this.spinnerF2F = null;
            this.spinnerEMA = null;
            this.spinnerOEF = null;
        }
        public function get isFullRedrawActive():Boolean{
            return (!((null == this.fullRedraw)));
        }
        public function activateFullRedraw():void{
            if (this.isFullRedrawActive){
                return;
            };
            this.deactivateFullRedraw();
            this.fullRedraw = new FullRedrawForcer();
            try {
                this.m_sprite.addChild(this.fullRedraw);
            } catch(err:Error) {
                fullRedraw = null;
                throw (err);
            };
        }
        public function deactivateFullRedraw():void{
            if (null != this.fullRedraw){
                this.m_sprite.removeChild(this.fullRedraw);
            };
            this.fullRedraw = null;
        }
        public function get keyCapture():Boolean{
            return (this.keysActive);
        }
        public function set keyCapture(_arg1:Boolean):void{
            this.keysActive = _arg1;
        }
        private function isEmpty(_arg1:DisplayObject):Boolean{
            if (!_arg1.visible){
                return (true);
            };
            if (_arg1.width != 0){
                return (false);
            };
            if (_arg1.height != 0){
                return (false);
            };
            var _local2:DisplayObjectContainer = (_arg1 as DisplayObjectContainer);
            if (null == _local2){
                return (true);
            };
            return ((_local2.numChildren <= 0));
        }
        private function prune_empties(_arg1:DisplayObject):void{
            var _local4:DisplayObject;
            var _local2:DisplayObjectContainer = (_arg1 as DisplayObjectContainer);
            if (null == _local2){
                return;
            };
            var _local3:int = (_local2.numChildren - 1);
            while (_local3 >= 0) {
                _local4 = _local2.getChildAt(_local3);
                if (!this.isEmpty(_local4)){
                } else {
                    _local2.removeChildAt(_local3);
                };
                _local3--;
            };
        }

    }
}//package zasp.Classes 
